<%@page import="java.util.UUID"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
%>
<script type="text/javascript">
var uuid='${uuid}'
/**
 * 每周期
 */
function everyTime(dom) {
	var item = $("input[name=v_" + dom.name + "]");
	item.val("*");
	item.change();
}

/**
 * 不指定
 */
function unAppoint(dom) {
	var name = dom.name;
	var val = "?";
	if (name == "year")
		val = "";
	var item = $("input[name=v_" + name + "]");
	item.val(val);
	item.change();
}

function appoint(dom) {

}

/**
 * 周期
 */
function cycle(dom) {
	var name = dom.name;
	var ns = $(dom).parent().find(".numberspinner");
	var start = ns.eq(0).val();
	var end = ns.eq(1).val();
	var item = $("input[name=v_" + name + "]");
	item.val(start + "-" + end);
	item.change();
}

/**
 * 从开始
 */
function startOn(dom) {
	var name = dom.name;
	var ns = $(dom).parent().find(".numberspinner");
	var start = ns.eq(0).val();
	var end = ns.eq(1).val();
	var item = $("input[name=v_" + name + "]");
	item.val(start + "/" + end);
	item.change();
}

function lastDay(dom){
	var item = $("input[name=v_" + dom.name + "]");
	item.val("L");
	item.change();
}

function weekOfDay(dom){
	var name = dom.name;
	var ns = $(dom).parent().find(".numberspinner");
	var start = ns.eq(0).val();
	var end = ns.eq(1).val();
	var item = $("input[name=v_" + name + "]");
	item.val(start + "#" + end);
	item.change();
}

function lastWeek(dom){
	var item = $("input[name=v_" + dom.name + "]");
	var ns = $(dom).parent().find(".numberspinner");
	var start = ns.eq(0).val();
	item.val(start+"L");
	item.change();
}

function workDay(dom) {
	var name = dom.name;
	var ns = $(dom).parent().find(".numberspinner");
	var start = ns.eq(0).val();
	var item = $("input[name=v_" + name + "]");
	item.val(start + "W");
	item.change();
}

function btnFan() {
    //获取参数中表达式的值
    var txt = $("#cron").val();
    if (txt) {
        var regs = txt.split(' ');
        $("input[name=v_second]").val(regs[0]);
        $("input[name=v_min]").val(regs[1]);
        $("input[name=v_hour]").val(regs[2]);
        $("input[name=v_day]").val(regs[3]);
        $("input[name=v_mouth]").val(regs[4]);
        $("input[name=v_week]").val(regs[5]);

        initObj(regs[0], "second");
        initObj(regs[1], "min");
        initObj(regs[2], "hour");
        initDay(regs[3]);
        initMonth(regs[4]);
        initWeek(regs[5]);

        if (regs.length > 6) {
            $("input[name=v_year]").val(regs[6]);
            initYear(regs[6]);
        }
    }
}

function initObj(strVal, strid) {
    var ary = null;
    var objRadio = $("input[name='" + strid + "'");
    if (strVal == "*") {
        objRadio.eq(0).attr("checked", "checked");
    } else if (strVal.split('-').length > 1) {
        ary = strVal.split('-');
        objRadio.eq(1).attr("checked", "checked");
        $("#" + strid + "Start_0").val(ary[0]);
        $("#" + strid + "End_0").val(ary[1]);
    } else if (strVal.split('/').length > 1) {
        ary = strVal.split('/');
        objRadio.eq(2).attr("checked", "checked");
        $("#" + strid + "Start_1").val(ary[0]);
        $("#" + strid + "End_1").val(ary[1]);
    } else {
        objRadio.eq(3).attr("checked", "checked");
        if (strVal != "?") {
            ary = strVal.split(",");
            for (var i = 0; i < ary.length; i++) {
                $("." + strid + "List input[value='" + ary[i] + "']").attr("checked", "checked");
            }
        }
    }
}

function initDay(strVal) {
    var ary = null;
    var objRadio = $("input[name='day'");
    if (strVal == "*") {
        objRadio.eq(0).attr("checked", "checked");
    } else if (strVal == "?") {
        objRadio.eq(1).attr("checked", "checked");
    } else if (strVal.split('-').length > 1) {
        ary = strVal.split('-');
        objRadio.eq(2).attr("checked", "checked");
        $("#dayStart_0").val(ary[0]);
        $("#dayEnd_0").val(ary[1]);
    } else if (strVal.split('/').length > 1) {
        ary = strVal.split('/');
        objRadio.eq(3).attr("checked", "checked");
        $("#dayStart_1").val(ary[0]);
        $("#dayEnd_1").val(ary[1]);
    } else if (strVal.split('W').length > 1) {
        ary = strVal.split('W');
        objRadio.eq(4).attr("checked", "checked");
        $("#dayStart_2").val(ary[0]);
    } else if (strVal == "L") {
        objRadio.eq(5).attr("checked", "checked");
    } else {
        objRadio.eq(6).attr("checked", "checked");
        ary = strVal.split(",");
        for (var i = 0; i < ary.length; i++) {
            $(".dayList input[value='" + ary[i] + "']").attr("checked", "checked");
        }
    }
}

function initMonth(strVal) {
    var ary = null;
    var objRadio = $("input[name='mouth'");
    if (strVal == "*") {
        objRadio.eq(0).attr("checked", "checked");
    } else if (strVal == "?") {
        objRadio.eq(1).attr("checked", "checked");
    } else if (strVal.split('-').length > 1) {
        ary = strVal.split('-');
        objRadio.eq(2).attr("checked", "checked");
        $("#mouthStart_0").val(ary[0]);
        $("#mouthEnd_0").val(ary[1]);
    } else if (strVal.split('/').length > 1) {
        ary = strVal.split('/');
        objRadio.eq(3).attr("checked", "checked");
        $("#mouthStart_1").val(ary[0]);
        $("#mouthEnd_1").val(ary[1]);

    } else {
        objRadio.eq(4).attr("checked", "checked");

        ary = strVal.split(",");
        for (var i = 0; i < ary.length; i++) {
            $(".mouthList input[value='" + ary[i] + "']").attr("checked", "checked");
        }
    }
}

function initWeek(strVal) {
    var ary = null;
    var objRadio = $("input[name='week'");
    if (!strVal || strVal == "*") {
        objRadio.eq(0).attr("checked", "checked");
    } else if (strVal == "?") {
        objRadio.eq(1).attr("checked", "checked");
    } else if (strVal.split('/').length > 1) {
        ary = strVal.split('/');
        objRadio.eq(2).attr("checked", "checked");
        $("#weekStart_0").val(ary[0]);
        $("#weekEnd_0").val(ary[1]);
    } else if (strVal.split('-').length > 1) {
        ary = strVal.split('-');
        objRadio.eq(3).attr("checked", "checked");
        $("#weekStart_1").val(ary[0]);
        $("#weekEnd_1").val(ary[1]);
    } else if (strVal.split('L').length > 1) {
        ary = strVal.split('L');
        objRadio.eq(4).attr("checked", "checked");
        $("#weekStart_2").val(ary[0]);
    } else {
        objRadio.eq(5).attr("checked", "checked");
        ary = strVal.split(",");
        for (var i = 0; i < ary.length; i++) {
            $(".weekList input[value='" + ary[i] + "']").attr("checked", "checked");
        }
    }
}

function initYear(strVal) {
    var ary = null;
    var objRadio = $("input[name='year'");
    if (strVal == "*") {
        objRadio.eq(1).attr("checked", "checked");
    } else if (strVal.split('-').length > 1) {
        ary = strVal.split('-');
        objRadio.eq(2).attr("checked", "checked");
        $("#yearStart_0").val('setValue', ary[0]);
        $("#yearEnd_0").val('setValue', ary[1]);
    }
}
</script>
<form method="post">
<div>
	<ul class="nav nav-tabs" role="tablist" id="tab_${uuid}">
		<li class="active"><a href="#second" data-toggle="tab">秒</a></li>
		<li><a href="#minute" data-toggle="tab">分</a></li>
		<li><a href="#hour" data-toggle="tab">时</a></li>
		<li><a href="#day" data-toggle="tab">日</a></li>
		<li><a href="#month" data-toggle="tab">月</a></li>
		<li><a href="#week" data-toggle="tab">周</a></li>
		<li><a href="#year" data-toggle="tab">年</a></li>
	</ul>
	
	<div class="tab-content">
		<div role="tabpanel" class="tab-pane active" id="second">
			<div class="form-group">
				<input name="second" onclick="everyTime(this)" type="radio">
				每秒 允许的通配符[, - * /]
			</div>
			<div class="form-group">
				<input name="second" onclick="cycle(this)" type="radio">
				周期从
				<input class="numberspinner" id="secondStart_0" style="width: 60px;" value="1" data-options="min:1,max:58">
				-
				<input class="numberspinner" id="secondEnd_0" style="width: 60px;" value="2" data-options="min:2,max:59">
				秒
			</div>
			<div class="form-group">
				<input name="second" onclick="startOn(this)" type="radio">
				从
				<input class="numberspinner" id="secondStart_1" style="width: 60px;" value="0" data-options="min:0,max:59">
				秒开始,每
				<input class="numberspinner" id="secondEnd_1" style="width: 60px;" value="1" data-options="min:1,max:59">
				秒执行一次
			</div>
			<div >
				<div class="form-group">
				<input name="second" id="sencond_appoint" type="radio">
				指定
				</div>
				<div class="imp secondList form-group">
					<input type="checkbox" value="0">00
					<input type="checkbox" value="1">01
					<input type="checkbox" value="2">02
					<input type="checkbox" value="3">03
					<input type="checkbox" value="4">04
					<input type="checkbox" value="5">05
					<input type="checkbox" value="6">06
					<input type="checkbox" value="7">07
					<input type="checkbox" value="8">08
					<input type="checkbox" value="9">09
					
				</div>
				
				<div class="imp secondList form-group">
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
				</div>
				
				<div class="imp secondList form-group">
					<input type="checkbox" value="20">20
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
					<input type="checkbox" value="24">24
					<input type="checkbox" value="25">25
					<input type="checkbox" value="26">26
					<input type="checkbox" value="27">27
					<input type="checkbox" value="28">28
					<input type="checkbox" value="29">29
				</div>
				
				<div class="imp secondList form-group">
					<input type="checkbox" value="30">30
					<input type="checkbox" value="31">31
					<input type="checkbox" value="32">32
					<input type="checkbox" value="33">33
					<input type="checkbox" value="34">34
					<input type="checkbox" value="35">35
					<input type="checkbox" value="36">36
					<input type="checkbox" value="37">37
					<input type="checkbox" value="38">38
					<input type="checkbox" value="39">39
				</div>
				
				<div class="imp secondList form-group">
					<input type="checkbox" value="40">40
					<input type="checkbox" value="41">41
					<input type="checkbox" value="42">42
					<input type="checkbox" value="43">43
					<input type="checkbox" value="44">44
					<input type="checkbox" value="45">45
					<input type="checkbox" value="46">46
					<input type="checkbox" value="47">47
					<input type="checkbox" value="48">48
					<input type="checkbox" value="49">49
				</div>
				
				<div class="imp secondList form-group">
					<input type="checkbox" value="50">50
					<input type="checkbox" value="51">51
					<input type="checkbox" value="52">52
					<input type="checkbox" value="53">53
					<input type="checkbox" value="54">54
					<input type="checkbox" value="55">55
					<input type="checkbox" value="56">56
					<input type="checkbox" value="57">57
					<input type="checkbox" value="58">58
					<input type="checkbox" value="59">59
				</div>
			</div>
		</div>
		<div role="tabpanel" class="tab-pane" id="minute">
			<div class="form-group">
				<input name="min" onclick="everyTime(this)" type="radio">分钟 允许的通配符[, - * /]
			</div>
			<div class="form-group">
				<input name="min" onclick="cycle(this)" type="radio">周期从
				<input class="numberspinner" id="minStart_0" style="width: 60px;" value="1" data-options="min:1,max:58">
				-
				<input class="numberspinner" id="minEnd_0" style="width: 60px;" value="2" data-options="min:2,max:59">
				分钟
			</div>
			<div class="form-group">
				<input name="min" onclick="startOn(this)" type="radio">
				从
				<input class="numberspinner" id="minStart_1" style="width: 60px;" value="0" data-options="min:0,max:59">
				分钟开始,每
				<input class="numberspinner" id="minEnd_1" style="width: 60px;" value="1" data-options="min:1,max:59">
				分钟执行一次
			</div>
			<div class="form-group">
				<input name="min" id="min_appoint" type="radio">
				指定
				<div class="imp minList">
					<input type="checkbox" value="0">00
					<input type="checkbox" value="1">01
					<input type="checkbox" value="2">02
					<input type="checkbox" value="3">03
					<input type="checkbox" value="4">04
					<input type="checkbox" value="5">05
					<input type="checkbox" value="6">06
					<input type="checkbox" value="7">07
					<input type="checkbox" value="8">08
					<input type="checkbox" value="9">09
				</div>
				
				<div class="imp minList">
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
				</div>
				
				<div class="imp minList">
					<input type="checkbox" value="20">20
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
					<input type="checkbox" value="24">24
					<input type="checkbox" value="25">25
					<input type="checkbox" value="26">26
					<input type="checkbox" value="27">27
					<input type="checkbox" value="28">28
					<input type="checkbox" value="29">29
				</div>
				
				<div class="imp minList">
					<input type="checkbox" value="30">30
					<input type="checkbox" value="31">31
					<input type="checkbox" value="32">32
					<input type="checkbox" value="33">33
					<input type="checkbox" value="34">34
					<input type="checkbox" value="35">35
					<input type="checkbox" value="36">36
					<input type="checkbox" value="37">37
					<input type="checkbox" value="38">38
					<input type="checkbox" value="39">39
				</div>
				
				<div class="imp minList">
					<input type="checkbox" value="40">40
					<input type="checkbox" value="41">41
					<input type="checkbox" value="42">42
					<input type="checkbox" value="43">43
					<input type="checkbox" value="44">44
					<input type="checkbox" value="45">45
					<input type="checkbox" value="46">46
					<input type="checkbox" value="47">47
					<input type="checkbox" value="48">48
					<input type="checkbox" value="49">49
				</div>
				
				<div class="imp minList">
					<input type="checkbox" value="50">50
					<input type="checkbox" value="51">51
					<input type="checkbox" value="52">52
					<input type="checkbox" value="53">53
					<input type="checkbox" value="54">54
					<input type="checkbox" value="55">55
					<input type="checkbox" value="56">56
					<input type="checkbox" value="57">57
					<input type="checkbox" value="58">58
					<input type="checkbox" value="59">59
				</div>
			</div>
		</div>
		<div role="tabpanel" class="tab-pane" id="hour">
			<div class="form-group">
				<input name="hour" onclick="everyTime(this)" type="radio">
				小时 允许的通配符[, - * /]
			</div>
			<div class="form-group">
				<input name="hour" onclick="cycle(this)" type="radio">
				周期从
				<input class="numberspinner" id="hourStart_0" style="width: 60px;" value="0" data-options="min:0,max:23">
				-
				<input class="numberspinner" id="hourEnd_1" style="width: 60px;" value="2" data-options="min:2,max:23">
				小时
			</div>
			
			<div class="form-group">
				<input name="hour" onclick="startOn(this)" type="radio">
				从 
				<input class="numberspinner" id="hourStart_1" style="width: 60px;" value="0" data-options="min:0,max:23">
				小时开始,每
				<input class="numberspinner" id="hourEnd_1" style="width: 60px;" value="1" data-options="min:1,max:23">
				小时执行一次
			</div>
			<div class="form-group">
				<input name="hour" id="hour_appoint" type="radio">
				指定
				<div class="imp hourList">
					AM:
					<input type="checkbox" value="0">00
					<input type="checkbox" value="1">01
					<input type="checkbox" value="2">02
					<input type="checkbox" value="3">03
					<input type="checkbox" value="4">04
					<input type="checkbox" value="5">05
					<input type="checkbox" value="6">06
					<input type="checkbox" value="7">07
					<input type="checkbox" value="8">08
					<input type="checkbox" value="9">09
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
				</div>
				<div class="imp hourList">
					PM:
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
					<input type="checkbox" value="20">20
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
				</div>
			</div>
		</div>
		<div role="tabpanel" class="tab-pane" id="day">
			<div class="form-group">
				<input name="day" onclick="everyTime(this)" type="radio">
				日 允许的通配符[, - * / L W]
			</div>
			<div class="form-group">
				<input name="day" onclick="unAppoint(this)" type="radio">
				不指定
			</div>
			<div class="form-group">
				<input name="day" onclick="cycle(this)" type="radio">
				周期从
				<input class="numberspinner" id="dayStart_0" style="width: 60px;" value="1" data-options="min:1,max:31">
				-
				<input class="numberspinner" id="dayEnd_0" style="width: 60px;" value="2" data-options="min:2,max:31">
				日
			</div>
			<div class="form-group">
				<input name="day" onclick="startOn(this)" type="radio">
				从
				<input class="numberspinner" id="dayStart_1" style="width: 60px;" value="1" data-options="min:1,max:31">
				日开始,每
				<input class="numberspinner" id="dayEnd_1" style="width: 60px;" value="1" data-options="min:1,max:31">
				天执行一次
			</div>
			<div class="form-group">
				<input name="day" onclick="workDay(this)" type="radio">
				每月
				<input class="numberspinner" id="dayStart_2" style="width: 60px;" value="1" data-options="min:1,max:31">
				号最近的那个工作日
			</div>
			<div class="form-group">
				<input name="day" onclick="lastDay(this)" type="radio">
				本月最后一天
			</div>
			<div class="form-group">
				<input  name="day" id="day_appoint" type="radio">
				指定
				<div class="imp dayList">
					<input type="checkbox" value="1">1
					<input type="checkbox" value="2">2
					<input type="checkbox" value="3">3
					<input type="checkbox" value="4">4
					<input type="checkbox" value="5">5
					<input type="checkbox" value="6">6
					<input type="checkbox" value="7">7
					<input type="checkbox" value="8">8
					<input type="checkbox" value="9">9
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
					<input type="checkbox" value="13">13
					<input type="checkbox" value="14">14
					<input type="checkbox" value="15">15
					<input type="checkbox" value="16">16
				</div>
				
				<div class="imp dayList">
					<input type="checkbox" value="17">17
					<input type="checkbox" value="18">18
					<input type="checkbox" value="19">19
					<input type="checkbox" value="20">20
					<input type="checkbox" value="21">21
					<input type="checkbox" value="22">22
					<input type="checkbox" value="23">23
					<input type="checkbox" value="24">24
					<input type="checkbox" value="25">25
					<input type="checkbox" value="26">26
					<input type="checkbox" value="27">27
					<input type="checkbox" value="28">28
					<input type="checkbox" value="29">29
					<input type="checkbox" value="30">30
					<input type="checkbox" value="31">31
				</div>
			</div>
		</div>
		<div role="tabpanel" class="tab-pane" id="month">
			<div class="form-group">
				<input name="mouth" onclick="everyTime(this)" type="radio">月 允许的通配符[, - * /]
			</div>
			<div class="form-group">
				<input name="mouth" onclick="unAppoint(this)" type="radio">不指定
			</div>
			<div class="form-group">
				<input name="mouth" onclick="cycle(this)" type="radio">周期从
				<input class="numberspinner" id="mouthStart_0" style="width: 60px;" value="1" data-options="min:1,max:12">
				-
				<input class="numberspinner" id="mouthEnd_0" style="width: 60px;" value="2" data-options="min:2,max:12">
				月
			</div>
			<div class="form-group">
				<input name="mouth" onclick="startOn(this)" type="radio">
				从
				<input class="numberspinner" id="mouthStart_1" style="width: 60px;" value="1" data-options="min:1,max:12">
				日开始,每
				<input class="numberspinner" id="mouthEnd_1" style="width: 60px;" value="1" data-options="min:1,max:12">
				月执行一次
			</div>
			<div class="form-group">
				<input name="mouth" id="mouth_appoint" type="radio">
				指定
				<div class="imp mouthList">
					<input type="checkbox" value="1">1
					<input type="checkbox" value="2">2
					<input type="checkbox" value="3">3
					<input type="checkbox" value="4">4
					<input type="checkbox" value="5">5
					<input type="checkbox" value="6">6
					
					<input type="checkbox" value="7">7
					<input type="checkbox" value="8">8
					<input type="checkbox" value="9">9
					<input type="checkbox" value="10">10
					<input type="checkbox" value="11">11
					<input type="checkbox" value="12">12
				</div>
			</div>
			
		</div>
		<div role="tabpanel" class="tab-pane" id="week">
			<div class="form-group">
				<input name="week" onclick="everyTime(this)" type="radio">
				周 允许的通配符[, - * / L #]
			</div>
			<div class="form-group">
				<input name="week" onclick="unAppoint(this)" type="radio">
				不指定
			</div>
			<div class="form-group">
				<input name="week" onclick="startOn(this)" type="radio">
				周期 从星期
				<input class="numberspinner" id="weekStart_0" style="width: 60px;" value="1" data-options="min:1,max:7">
				-
				<input class="numberspinner" id="weekEnd_0" style="width: 60px;" value="2" data-options="min:2,max:7">
			</div>
			<div class="form-group">
				<input name="week" onclick="weekOfDay(this)" type="radio">
				第
				<input class="numberspinner" id="weekStart_1" style="width: 60px;" value="1" data-options="min:1,max:4">
				周的星期
				<input class="numberspinner" id="weekEnd_1" style="width: 60px;" value="1" data-options="min:1,max:7">
			</div>
			<div class="form-group">
				<input name="week" onclick="lastWeek(this)" type="radio">
				本月最后一个星期
				<input class="numberspinner" id="weekStart_2" style="width: 60px;" value="1" data-options="min:1,max:7">
			</div>
			<div class="form-group">
				<input name="week" id="week_appoint" type="radio">
				指定
			</div>
			<div class="imp weekList form-group">
				<input type="checkbox" value="1">1
				<input type="checkbox" value="2">2
				<input type="checkbox" value="3">3
				<input type="checkbox" value="4">4
				<input type="checkbox" value="5">5
				<input type="checkbox" value="6">6
				<input type="checkbox" value="7">7
			</div>
		</div>
		<div role="tabpanel" class="tab-pane" id="year">
			<div class="form-group">
			<input name="year" onclick="unAppoint(this)" type="radio">
			不指定 允许的通配符[, - * /] 非必填
			</div>
			<div class="form-group">
				<input name="year" onclick="everyTime(this)" type="radio">
				每年
				</div>
				<div>
					<input name="year" onclick="cycle(this)" type="radio">
					周期 从
					<input class="numberspinner" id="yearStart_0" style="width: 90px;" value="2013" data-options="min:2013,max:3000">
					-
					<input class="numberspinner" id="yearEnd_0" style="width: 90px;" value="2014" data-options="min:2014,max:3000">
				</div>
			</div>
		
	</div>
	
</div>

<fieldset style="border-radius: 3px;margin: 10px 0px"><LEGEND>表达式</LEGEND>   
	<table>
		<tr>
			<td></td>
			<td>秒</td>
			<td>分钟</td>
			<td>小时</td>
			<td>日</td>
			<td>月</td>
			<td>星期</td>
			<td>年</td>
		</tr>
		<tr>
			<td>表达式字段: </td>
			<td>
				<input name="v_second" type="text" readonly="readonly" value="*" style="width:60px">
			</td>
			<td>
				<input name="v_min" type="text" readonly="readonly" value="*" style="width:60px">
			</td>
			<td>
				<input name="v_hour" type="text" readonly="readonly" value="*" style="width:60px">
			</td>
			<td>
				<input name="v_day" type="text" readonly="readonly" value="*" style="width:60px">
			</td>
			<td>
				<input name="v_mouth" type="text" readonly="readonly" value="*" style="width:60px">
			</td>
			<td>
				<input name="v_week" type="text" readonly="readonly" value="?" style="width:60px">
			</td>
			<td>
				<input name="v_year" type="text" readonly="readonly" value="" style="width:60px">
			</td>
		</tr>
		<tr>
			<td>Cron 表达式:</td>
			<td colspan="3"><input name="cron" id="cron" type="text" value="* * * * * ?" style="width:180px"></td>
			<td colspan="3"><input id="btnFan" type="button" value="反解析到UI "></td>
		</tr>
	</table>
</fieldset>
</form>
<nav class="navbar navbar-default">
  <div class="container-fluid">
  	<div class="collapse navbar-collapse">
  		<ul class="nav navbar-nav navbar-right">
	  		<li>
	  			<button type="button" class="btn btn-primary navbar-btn" id="cronSubmitBt">确定</button>
	  		</li>
	  	</ul>
       </div>
  </div>
</nav>
<script type="text/javascript">



$(function() {
	$(".numberspinner").blur(function(){
		$(this).closest("div.form-group").children().eq(0).click();
	});

	var vals = $("input[name^='v_']");
	var cron = $("#cron");
	vals.change(function() {
		var item = [];
		vals.each(function() {
			item.push(this.value);
		});
		
		//TODO
		var currentIndex = 0;
        $("#tab_"+uuid+">li").each(function(i, item) {
            if ($(item).hasClass("active")) {
                currentIndex = i;
                return false
            }
        });
        for (var i = currentIndex; i >= 1; i--) {
            if (item[i] != "*" && item[i - 1] == "*") {
                item[i - 1] = "0"
            }
        }
        if (item[currentIndex] == "*") {
            for (var i = currentIndex + 1; i < item.length; i++) {
                if (i == 5) {
                    item[i] = "?"
                } else {
                    item[i] = "*"
                }
            }
        }
		
		cron.val(item.join(" "));
		btnFan();
	});
	
	var secondList = $(".secondList").children();
	$("#sencond_appoint").click(function(){
		if(this.checked){
			secondList.eq(0).change();
		}
	});

	secondList.change(function() {
		var sencond_appoint = $("#sencond_appoint").prop("checked");
		if (sencond_appoint) {
			var vals = [];
			secondList.each(function() {
				if (this.checked) {
					vals.push(this.value);
				}
			});
			var val = "?";
			if (vals.length > 0 && vals.length < 59) {
				val = vals.join(","); 
			}else if(vals.length == 59){
				val = "*";
			}
			var item = $("input[name=v_second]");
			item.val(val);
			item.change();
		}
	});
	
	var minList = $(".minList").children();
	$("#min_appoint").click(function(){
		if(this.checked){
			minList.eq(0).change();
		}
	});
	
	minList.change(function() {
		var min_appoint = $("#min_appoint").prop("checked");
		if (min_appoint) {
			var vals = [];
			minList.each(function() {
				if (this.checked) {
					vals.push(this.value);
				}
			});
			var val = "?";
			if (vals.length > 0 && vals.length < 59) {
				val = vals.join(",");
			}else if(vals.length == 59){
				val = "*";
			}
			var item = $("input[name=v_min]");
			item.val(val);
			item.change();
		}
	});
	
	var hourList = $(".hourList").children();
	$("#hour_appoint").click(function(){
		if(this.checked){
			hourList.eq(0).change();
		}
	});
	
	hourList.change(function() {
		var hour_appoint = $("#hour_appoint").prop("checked");
		if (hour_appoint) {
			var vals = [];
			hourList.each(function() {
				if (this.checked) {
					vals.push(this.value);
				}
			});
			var val = "?";
			if (vals.length > 0 && vals.length < 24) {
				val = vals.join(",");
			}else if(vals.length == 24){
				val = "*";
			}
			var item = $("input[name=v_hour]");
			item.val(val);
			item.change();
		}
	});
	
	var dayList = $(".dayList").children();
	$("#day_appoint").click(function(){
		if(this.checked){
			dayList.eq(0).change();
		}
	});
	
	dayList.change(function() {
		var day_appoint = $("#day_appoint").prop("checked");
		if (day_appoint) {
			var vals = [];
			dayList.each(function() {
				if (this.checked) {
					vals.push(this.value);
				}
			});
			var val = "?";
			if (vals.length > 0 && vals.length < 31) {
				val = vals.join(",");
			}else if(vals.length == 31){
				val = "*";
			}
			var item = $("input[name=v_day]");
			item.val(val);
			item.change();
		}
	});
	
	var mouthList = $(".mouthList").children();
	$("#mouth_appoint").click(function(){
		if(this.checked){
			mouthList.eq(0).change();
		}
	});
	
	mouthList.change(function() {
		var mouth_appoint = $("#mouth_appoint").prop("checked");
		if (mouth_appoint) {
			var vals = [];
			mouthList.each(function() {
				if (this.checked) {
					vals.push(this.value);
				}
			});
			var val = "?";
			if (vals.length > 0 && vals.length < 12) {
				val = vals.join(",");
			}else if(vals.length == 12){
				val = "*";
			}
			var item = $("input[name=v_mouth]");
			item.val(val);
			item.change();
		}
	});
	
	var weekList = $(".weekList").children();
	$("#week_appoint").click(function(){
		if(this.checked){
			weekList.eq(0).change();
		}
	});
	
	weekList.change(function() {
		var week_appoint = $("#week_appoint").prop("checked");
		if (week_appoint) {
			var vals = [];
			weekList.each(function() {
				if (this.checked) {
					vals.push(this.value);
				}
			});
			var val = "?";
			if (vals.length > 0 && vals.length < 7) {
				val = vals.join(",");
			}else if(vals.length == 7){
				val = "*";
			}
			var item = $("input[name=v_week]");
			item.val(val);
			item.change();
		}
	});
	
	var paramCon='${param.cron}';
	if(paramCon){
		paramCon=Base64.decode(paramCon);
		$("#cron").val(paramCon);
	}
	$("#btnFan").click(function(){
		btnFan();
	});
	btnFan();
	
	$("#cronSubmitBt").click(function(){
		webUtils.fire("cron.select",$("#cron").val(),true);
	});
});
</script>
